unit ReproduzirMFMFD;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, Buttons;

type
  TFormReproduzirMFMFD = class(TForm)
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    MaskEdit1: TMaskEdit;
    Label3: TLabel;
    MaskEdit2: TMaskEdit;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Edit1: TEdit;
    Label4: TLabel;
    Edit2: TEdit;
    BitBtn1: TBitBtn;
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure RadioButton5Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormReproduzirMFMFD: TFormReproduzirMFMFD;
  tipo:String = '3';

implementation

uses principal, Retorno, declaracoes, funcoesapoio;

{$R *.dfm}

procedure TFormReproduzirMFMFD.RadioButton1Click(Sender: TObject);
begin
        Tipo:= '0';
end;

procedure TFormReproduzirMFMFD.RadioButton2Click(Sender: TObject);
begin
        Tipo:= '1';

end;

procedure TFormReproduzirMFMFD.RadioButton3Click(Sender: TObject);
begin
        Tipo:= '2';

end;

procedure TFormReproduzirMFMFD.RadioButton5Click(Sender: TObject);
begin
        Tipo:= '3';
end;

procedure TFormReproduzirMFMFD.BitBtn1Click(Sender: TObject);
begin
        FormPrincipal.Statusbar1.Panels[0].Text:='Reproduzir Memória Fiscal MFD'; WaitProcess;
        if not FileExists('C:\SWEDA\MF.BIN') Then
        begin
                resposta:= ECF_DownloadMF('C:\SWEDA\MF.BIN');
                FormPrincipal.Memo1.Lines.Add('Download MF:'+inttostr(Resposta));
        end;
        Resposta:= ECF_ReproduzirMemoriaFiscalMFD(tipo,MaskEdit1.Text, MaskEdit2.Text,Edit1.Text,Edit2.Text);

        FormPrincipal.Memo1.Lines.Add('Reproduzir Memória Fiscal MFD:'+inttostr(Resposta));
        FormPrincipal.Memo1.Lines.Add('');

        if Resposta = 1 then
        if MessageDlg('Deseja abrir o arquivo '+Edit1.Text+' ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
                FormPrincipal.OpenDialog1.FileName:=Edit1.Text ;
                FormPrincipal.OpenDialog1.Execute;
                FormRetorno.Caption:=FormPrincipal.OpenDialog1.FileName;
                FormRetorno.RichEdit1.Lines.LoadFromFile(FormPrincipal.OpenDialog1.FileName);
                FormRetorno.Show;
        end;

        VerificaRetornoFuncao(Resposta);
        Refresh;

end;

end.
